###
# Author : pepper (Shane Culpepper)
# Date   : Thu 11 Mar 2010
#
# A general makefile that will automatically make any project where all of the
# source and header files are in one directory.
#
# If there are extra source or header files in the directory that are not part
# of the project they should be moved or renamed, or else the SRC and HDR
# variables should be set manually otherwise compilation may fail.
#
# For more information about makefiles, check here:
#     http://www.gnu.org/software/make/manual/make.html
###

# The name of the applications we're trying to generate
TARGET = parse_words

TARGET2 = unparse_words


SRC = libutil.c llist.c parse_words.c
SRC2 = libutil.c llist.c unparse_words.c
HDR = libutil.h llist.h

# The following three lines can be used to automatically generate the SRC, HDR
# and OBJ variables instead of doing it statically as above
#SRC := $(wildcard *.c)
#HDR := $(wildcard *.h)
OBJ := $(SRC:.c=.o)
OBJ2 := $(SRC2:.c=.o)

# These variables are used by make in all of it's automatic rules.
# Specifically, use CFLAGS for the "-g -O0" option if you want to do debugging,
# and LDFLAGS for the "-lm" option if you are using the math library.
CC = gcc
#CFLAGS = -W -Wall -ansi -O3 -D_XOPEN_SOURCE=500
CFLAGS = -W -Wall -ansi -g -O0 -D_XOPEN_SOURCE=500
LDFLAGS = -lm

all : $(TARGET) $(TARGET2)

$(TARGET) : $(OBJ)
	$(CC) $(LDFLAGS) -o $@ $(OBJ)

$(TARGET2) : $(OBJ2)
	$(CC) $(LDFLAGS) -o $@ $(OBJ2)

# This generates the dependencies between your various .c and .h files, using
# the c compiler's -MM option.
depend : $(SRC) $(SRC2) $(HDR)
	$(CC) $(CFLAGS) -MM $(SRC) > depend
	$(CC) $(CFLAGS) -MM $(SRC2) >> depend

# This includes the dependencies made with the previous rule, and in fact forces
# them to be generated.
-include depend

# The rules below clean up any files generated by the make process.  clean
# should be run to clear out the temporary files, and clobber should be run if
# you modify your makefile (for example to change the CFLAGS or LDFLAGS options)
# so that you can get a clean recompile.
.PHONY : test clean

test :
	echo "TBD"

clean :
	-rm -f $(TARGET2) $(OBJ2)
	-rm -f depend
	-rm -f $(TARGET) $(OBJ)
	-rm -f *~ 
